﻿#region NeoPatterns
// 
// NeoPatterns framework is released under LGPLv3 license.
// See http://www.opensource.org/licenses/lgpl-3.0.html for more details.
// 
// Please visit http://neopatterns.wikidot.com for more information about NeoPatterns
// 
// Copyright (c) Pascal Craponne 2008
// 
#endregion

using System.Reflection;

namespace NeoPatterns.Core.Aop
{
    /// <summary>
    /// A default implementation for IClaimingAdvisor
    /// To ease access to property
    /// </summary>
    /// <typeparam name="TClaim"></typeparam>
    public abstract class ClaimingAdvisor<TClaim> : IClaimingAdvisor
    {
        public virtual TClaim GetClaims(object proxy)
        {
            return (TClaim)Claims.GetSetMethod().Invoke(proxy, null);
        }

        public virtual void SetClaims(object proxy, TClaim claim)
        {
            Claims.GetSetMethod().Invoke(proxy, new object[] { claim });
        }

        /// <summary>
        /// Called on advice interception
        /// </summary>
        /// <param name="invocation"></param>
        public abstract void Advise(IInvocation invocation);

        /// <summary>
        /// Claims property is stored in the proxy object,
        /// to be used for private purposes by advisor
        /// </summary>
        public PropertyInfo Claims { get; set; }

        public virtual void InitializeClaims(object target)
        {
        }
    }
}
